<?php

require("./Conn.php");

//-------------------------------------------------------
if (!isset($_POST['req'])) {
    die("No request provided.");
} else if (filter_input(INPUT_POST, 'req') == "Redimensionando") {//YA FUNCIONA 


    $NomTablespace = filter_input(INPUT_POST, 'tablespace'); //obtengo el array del javascript
    //ESTE QUERY SACA LA DIRECCION DEL TABLESPACE A AMPLIAR
    $query1 = "Select SUBSTR(d.file_name,1,80) 
    FROM DBA_FREE_SPACE f, DBA_DATA_FILES d, DBA_TABLESPACES t
    WHERE t.tablespace_name = d.tablespace_name AND
    f.tablespace_name(+) = d.tablespace_name 
    AND f.file_id(+) = d.file_id AND
    t.tablespace_name = '".$NomTablespace."' GROUP BY t.tablespace_name,
    d.file_name, t.pct_increase, t.status";

    $l = oci_parse($conn, $query1);
    oci_execute($l);
    $res;
    
    while (($row = oci_fetch_row($l)) != false) {
    foreach ($row as $item) {
        $res = $item ;
    }
}
     echo "".$query1."</br>";
    
    //EXTIENDO EL DATAFILE   
    $query2 = "ALTER DATABASE
    DATAFILE '".$res."' AUTOEXTEND ON NEXT 1M MAXSIZE 40M";

    //echo $query2;
    
    $s = oci_parse($conn, $query2);
    oci_execute($s);
   

    
}
//---------------------------------------------------

if (filter_input(INPUT_POST, 'req') == "CreandoDatafile") {//YA FUNCIONA BIEN

    $NomTablespace = filter_input(INPUT_POST, 'tablespace'); //obtengo el array del javascript
    //QUERY PARA CREAR UN NUEVO DATAFILE EN UN TABLESPACE
       
    $query3 = "ALTER TABLESPACE ".$NomTablespace."  ADD
    DATAFILE 'E:\APP\JUANCHO92\ORADATA\ORCL\datafile_e.DBF' SIZE
    100M AUTOEXTEND
    ON NEXT 1M MAXSIZE 1000M";
    
   // echo $query3;
       
    $q = oci_parse($conn, $query3);
    oci_execute($q);
    
   print(json_encode("ya cree datafile nuevo"));
}

//---------------------------------------------------